package com.example.bookmanager.Service;

import com.example.bookmanager.Enum.Enums;
import com.example.bookmanager.Mapper.BookMapper;
import com.example.bookmanager.Model.BookInfo;
import com.example.bookmanager.Model.PageResult;
import com.example.bookmanager.Model.RequestPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.awt.print.Book;
import java.util.List;

@Service
public class BookService {
    @Autowired
    private BookMapper bookMapper;

    public Integer addBook(BookInfo book) {
        return bookMapper.addBook(book);
    }

    public PageResult<BookInfo> getBookList(PageResult pageResult) {
        Integer count = bookMapper.count();
        List<BookInfo> bookList = bookMapper.getBookList(pageResult.requestPage.getOffset(), pageResult.requestPage.getPageSize());
        for (BookInfo book : bookList) {
            book.setStatusCN(Enums.getEnum(book.getStatus()).getName());
        }
        return new PageResult<>(bookList,count,pageResult.requestPage);
    }

    public BookInfo getBook(Integer bookId) {
        return bookMapper.getBook(bookId);
    }

    public Integer updateBook(BookInfo book) {
        return bookMapper.updateBook(book);
    }

    public Integer batchDelete(@RequestParam List<Integer> ids) {
        return bookMapper.batchDelete(ids);
    }
}
